// 类型定义模块
// 包含所有期权数据结构和枚举类型

use chrono::NaiveDate;
use serde::{Deserialize, Serialize};

/// 统一的 Result 类型，使用 anyhow 进行错误处理
pub type Result<T> = anyhow::Result<T>;

/// 金融期权标的枚举
/// 
/// 包含上交所、深交所和中金所的期权标的
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum FinanceSymbol {
    Sse50Etf,      // 上证50ETF
    Sse300Etf,     // 沪深300ETF
    Sse500Etf,     // 中证500ETF
    SseKc50Etf,    // 科创50ETF
    SseKc50EtfYfd, // 科创50ETF（易方达）
    Szse300Etf,    // 深交所300ETF
    CffexIO,       // 中金所沪深300指数
    CffexMO,       // 中金所中证1000指数
    CffexHO,       // 中金所上证50指数
}

/// 上交所标的物枚举
/// 
/// 用于查询上交所标的物快照数据
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum SseUnderlying {
    HuaXia50,      // 华夏上证50ETF
    HuaTai300,     // 华泰沪深300ETF
    NanFang500,    // 南方中证500ETF
    KeChuang50,    // 科创50ETF
    KeChuang50Yfd, // 科创50ETF（易方达）
}

/// 中金所指数期权枚举
/// 
/// 用于标识中金所三大指数期权
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub enum CffexIndex {
    IO, // 沪深300指数期权
    MO, // 中证1000指数期权
    HO, // 上证50指数期权
}

/// 期权到期月份
/// 
/// 支持 YYMM 或 YYYYMM 两种格式
/// 例如: "2511" 或 "202511"
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EndMonth(pub String);

impl EndMonth {
    /// 创建新的到期月份
    pub fn new<S: Into<String>>(s: S) -> Self { Self(s.into()) }
}

/// 金融期权行情数据
/// 
/// 用于期权看板数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FinanceQuote {
    pub date_time: String,      // 日期时间
    pub contract_id: String,    // 合约代码
    pub last: Option<f64>,      // 最新价
    pub change_pct: Option<f64>, // 涨跌幅(%)
    pub prev_settle: Option<f64>, // 前结算价
    pub strike: Option<f64>,    // 行权价
}

/// 上交所标的物行情
/// 
/// 标的证券的实时行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseUnderlyingQuote {
    pub code: String,           // 标的代码
    pub name: String,           // 标的名称
    pub last: Option<f64>,      // 最新价
    pub change: Option<f64>,    // 涨跌额
    pub change_pct: Option<f64>, // 涨跌幅(%)
    pub volume_lots: Option<f64>, // 成交量(手)
    pub amount_10k: Option<f64>,  // 成交额(万元)
    pub update_time: String,    // 更新时间
}

/// 东方财富期权行情快照
/// 
/// 全市场期权实时行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct EmOptionTick {
    #[serde(rename = "代码")]
    pub code: String,              // 期权代码
    #[serde(rename = "名称")]
    pub name: String,              // 期权名称
    #[serde(rename = "最新价")]
    pub last: Option<f64>,         // 最新价
    #[serde(rename = "涨跌额")]
    pub change: Option<f64>,       // 涨跌额
    #[serde(rename = "涨跌幅")]
    pub change_pct: Option<f64>,   // 涨跌幅(%)
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,       // 成交量
    #[serde(rename = "成交额")]
    pub amount: Option<f64>,       // 成交额
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>, // 持仓量
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,       // 行权价
    #[serde(rename = "剩余天数")]
    pub days_remaining: Option<i64>, // 距离到期剩余天数
}

/// 交易日期
/// 
/// 封装 NaiveDate 用于日期处理
#[derive(Debug, Clone, Copy, Serialize, Deserialize)]
pub struct TradeDate(pub NaiveDate);

// ============ 东方财富特色数据 ============

/// 期权价值分析数据
/// 
/// 包含期权的内在价值、时间价值、隐含波动率等指标
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionValueAnalysis {
    #[serde(rename = "期权代码")]
    pub code: String,
    #[serde(rename = "期权名称")]
    pub name: String,
    #[serde(rename = "最新价")]
    pub last: Option<f64>,
    #[serde(rename = "涨跌幅")]
    pub change_pct: Option<f64>,
    #[serde(rename = "内在价值")]
    pub intrinsic_value: Option<f64>,
    #[serde(rename = "时间价值")]
    pub time_value: Option<f64>,
    #[serde(rename = "杠杆比率")]
    pub leverage: Option<f64>,
    #[serde(rename = "实际杠杆")]
    pub actual_leverage: Option<f64>,
    #[serde(rename = "标的最新价")]
    pub underlying_last: Option<f64>,
    #[serde(rename = "标的近一年波动率")]
    pub underlying_volatility: Option<f64>,
    #[serde(rename = "到期日")]
    pub expire_date: String,
}

/// 期权风险分析数据
/// 
/// 包含期权的 Greeks 指标（Delta、Gamma、Vega、Theta、Rho）
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionRiskAnalysis {
    #[serde(rename = "期权代码")]
    pub code: String,
    #[serde(rename = "期权名称")]
    pub name: String,
    #[serde(rename = "最新价")]
    pub last: Option<f64>,
    #[serde(rename = "涨跌幅")]
    pub change_pct: Option<f64>,
    #[serde(rename = "Delta")]
    pub delta: Option<f64>,
    #[serde(rename = "Gamma")]
    pub gamma: Option<f64>,
    #[serde(rename = "Vega")]
    pub vega: Option<f64>,
    #[serde(rename = "Theta")]
    pub theta: Option<f64>,
    #[serde(rename = "Rho")]
    pub rho: Option<f64>,
    #[serde(rename = "隐含波动率")]
    pub implied_volatility: Option<f64>,
    #[serde(rename = "到期日")]
    pub expire_date: String,
}

/// 期权折溢价分析数据
/// 
/// 包含期权的折溢价率、盈亏平衡价等指标
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionPremiumAnalysis {
    #[serde(rename = "期权代码")]
    pub code: String,
    #[serde(rename = "期权名称")]
    pub name: String,
    #[serde(rename = "最新价")]
    pub last: Option<f64>,
    #[serde(rename = "涨跌幅")]
    pub change_pct: Option<f64>,
    #[serde(rename = "折溢价率")]
    pub premium_rate: Option<f64>,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
    #[serde(rename = "标的最新价")]
    pub underlying_last: Option<f64>,
    #[serde(rename = "标的涨跌幅")]
    pub underlying_change_pct: Option<f64>,
    #[serde(rename = "盈亏平衡价")]
    pub break_even: Option<f64>,
    #[serde(rename = "到期日")]
    pub expire_date: String,
}

/// 期权分时行情数据
/// 
/// 包含期权的分钟级行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionMinute {
    #[serde(rename = "时间")]
    pub time: String,
    #[serde(rename = "最新价")]
    pub close: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "成交额")]
    pub amount: Option<f64>,
}

// ============ 上交所/深交所数据 ============

/// 上交所期权风险指标
/// 
/// 上交所公布的期权风险指标数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseRiskIndicator {
    #[serde(rename = "TRADE_DATE")]
    pub trade_date: String,
    #[serde(rename = "SECURITY_ID")]
    pub security_id: String,
    #[serde(rename = "DELTA_VALUE")]
    pub delta: Option<f64>,
    #[serde(rename = "GAMMA_VALUE")]
    pub gamma: Option<f64>,
    #[serde(rename = "THETA_VALUE")]
    pub theta: Option<f64>,
    #[serde(rename = "VEGA_VALUE")]
    pub vega: Option<f64>,
    #[serde(rename = "RHO_VALUE")]
    pub rho: Option<f64>,
    #[serde(rename = "IMPLC_VOLATLTY")]
    pub implied_volatility: Option<f64>,
}

/// 上交所当日期权合约信息
/// 
/// 包含合约的基本信息和到期日等
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseCurrentDayContract {
    #[serde(rename = "合约编码")]
    pub contract_code: String,
    #[serde(rename = "合约交易代码")]
    pub contract_id: String,
    #[serde(rename = "合约简称")]
    pub contract_name: String,
    #[serde(rename = "标的证券代码")]
    pub underlying_code: String,
    #[serde(rename = "标的证券简称")]
    pub underlying_name: String,
    #[serde(rename = "期权类型")]
    pub option_type: String,
    #[serde(rename = "行权价格")]
    pub strike: Option<f64>,
    #[serde(rename = "合约单位")]
    pub contract_unit: Option<i64>,
    #[serde(rename = "期权行权日")]
    pub exercise_date: String,
    #[serde(rename = "行权交收日")]
    pub delivery_date: String,
    #[serde(rename = "到期日")]
    pub expire_date: String,
    #[serde(rename = "开始日期")]
    pub start_date: String,
}

/// 深交所当日期权合约信息
/// 
/// 包含合约的基本信息和到期日等
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SzseCurrentDayContract {
    #[serde(rename = "序号")]
    pub seq: Option<i64>,
    #[serde(rename = "合约编码")]
    pub contract_code: String,
    #[serde(rename = "合约代码")]
    pub contract_id: String,
    #[serde(rename = "合约简称")]
    pub contract_name: String,
    #[serde(rename = "标的代码")]
    pub underlying_code: String,
    #[serde(rename = "标的简称")]
    pub underlying_name: String,
    #[serde(rename = "期权类型")]
    pub option_type: String,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
    #[serde(rename = "合约单位")]
    pub contract_unit: Option<i64>,
    #[serde(rename = "期权行权日")]
    pub exercise_date: String,
    #[serde(rename = "交易日期")]
    pub trade_date: String,
}

/// 上交所期权每日统计数据
/// 
/// 包含成交量、持仓量等统计指标
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseDailyStats {
    #[serde(rename = "合约标的代码")]
    pub underlying_code: String,
    #[serde(rename = "合约标的名称")]
    pub underlying_name: String,
    #[serde(rename = "合约数量")]
    pub contract_count: Option<i64>,
    #[serde(rename = "总成交额")]
    pub total_amount: Option<f64>,
    #[serde(rename = "总成交量")]
    pub total_volume: Option<f64>,
    #[serde(rename = "认购成交量")]
    pub call_volume: Option<f64>,
    #[serde(rename = "认沽成交量")]
    pub put_volume: Option<f64>,
    #[serde(rename = "未平仓合约总数")]
    pub total_open_interest: Option<f64>,
    #[serde(rename = "未平仓认购合约数")]
    pub call_open_interest: Option<f64>,
    #[serde(rename = "未平仓认沽合约数")]
    pub put_open_interest: Option<f64>,
    #[serde(rename = "交易日")]
    pub trade_date: String,
}

/// 深交所期权每日统计数据
/// 
/// 包含成交量、持仓量等统计指标
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SzseDailyStats {
    #[serde(rename = "合约标的代码")]
    pub underlying_code: String,
    #[serde(rename = "合约标的名称")]
    pub underlying_name: String,
    #[serde(rename = "成交量")]
    pub total_volume: Option<f64>,
    #[serde(rename = "认购成交量")]
    pub call_volume: Option<f64>,
    #[serde(rename = "认沽成交量")]
    pub put_volume: Option<f64>,
    #[serde(rename = "成交额")]
    pub total_amount: Option<f64>,
    #[serde(rename = "未平仓合约总数")]
    pub total_open_interest: Option<f64>,
    #[serde(rename = "未平仓认购合约数")]
    pub call_open_interest: Option<f64>,
    #[serde(rename = "未平仓认沽合约数")]
    pub put_open_interest: Option<f64>,
    #[serde(rename = "交易日")]
    pub trade_date: String,
}

// ============ 新浪财经数据 ============

/// 新浪-中金所期权合约
/// 
/// T型报价中的单个行权价对应的看涨和看跌期权数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SinaCffexContract {
    #[serde(rename = "看涨合约-买量")]
    pub call_bid_volume: Option<f64>,
    #[serde(rename = "看涨合约-买价")]
    pub call_bid_price: Option<f64>,
    #[serde(rename = "看涨合约-最新价")]
    pub call_last: Option<f64>,
    #[serde(rename = "看涨合约-卖价")]
    pub call_ask_price: Option<f64>,
    #[serde(rename = "看涨合约-卖量")]
    pub call_ask_volume: Option<f64>,
    #[serde(rename = "看涨合约-持仓量")]
    pub call_open_interest: Option<f64>,
    #[serde(rename = "看涨合约-涨跌")]
    pub call_change: Option<f64>,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
    #[serde(rename = "看涨合约-标识")]
    pub call_symbol: String,
    #[serde(rename = "看跌合约-买量")]
    pub put_bid_volume: Option<f64>,
    #[serde(rename = "看跌合约-买价")]
    pub put_bid_price: Option<f64>,
    #[serde(rename = "看跌合约-最新价")]
    pub put_last: Option<f64>,
    #[serde(rename = "看跌合约-卖价")]
    pub put_ask_price: Option<f64>,
    #[serde(rename = "看跌合约-卖量")]
    pub put_ask_volume: Option<f64>,
    #[serde(rename = "看跌合约-持仓量")]
    pub put_open_interest: Option<f64>,
    #[serde(rename = "看跌合约-涨跌")]
    pub put_change: Option<f64>,
    #[serde(rename = "看跌合约-标识")]
    pub put_symbol: String,
}

/// 新浪-中金所期权实时行情
/// 
/// 包含指定合约的完整T型报价数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SinaCffexSpot {
    #[serde(rename = "合约代码")]
    pub symbol: String,
    #[serde(rename = "合约列表")]
    pub contracts: Vec<SinaCffexContract>,
}

/// 新浪-中金所期权日频数据
/// 
/// 包含期权合约的历史日线数据（OHLCV）
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SinaCffexDaily {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
}

/// 上交所期权合约信息
/// 
/// 用于新浪接口的上交所期权合约基本信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseContract {
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "合约简称")]
    pub contract_name: String,
    #[serde(rename = "标的代码")]
    pub underlying_code: String,
    #[serde(rename = "标的名称")]
    pub underlying_name: String,
    #[serde(rename = "期权类型")]
    pub option_type: String,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
    #[serde(rename = "到期日")]
    pub expire_date: String,
}

/// 上交所期权实时价格
/// 
/// 用于新浪接口的上交所期权实时行情
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseSpotPrice {
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "最新价")]
    pub last: Option<f64>,
    #[serde(rename = "涨跌幅")]
    pub change_pct: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
}

/// 上交所期权Greeks指标
/// 
/// 用于新浪接口的上交所期权Greeks指标数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseGreeks {
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "Delta")]
    pub delta: Option<f64>,
    #[serde(rename = "Gamma")]
    pub gamma: Option<f64>,
    #[serde(rename = "Vega")]
    pub vega: Option<f64>,
    #[serde(rename = "Theta")]
    pub theta: Option<f64>,
    #[serde(rename = "Rho")]
    pub rho: Option<f64>,
    // 以下字段来自 hq.sinajs.cn 的 CON_SO_ 接口
    #[serde(rename = "期权合约简称")]
    pub contract_name: String,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "隐含波动率")]
    pub implied_volatility: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "交易代码")]
    pub trade_code: String,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
    #[serde(rename = "最新价")]
    pub last: Option<f64>,
    #[serde(rename = "理论价值")]
    pub theoretical_value: Option<f64>,
}

/// 上交所期权分时数据
/// 
/// 用于新浪接口的上交所期权分钟级行情
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseMinute {
    #[serde(rename = "时间")]
    pub time: String,
    #[serde(rename = "价格")]
    pub price: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
}

/// 金融期权分钟数据（完整字段）
/// 
/// 与 AkShare Python 版对齐，包含日期、时间、价格、均价、成交量
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct FinanceMinute {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "时间")]
    pub time: String,
    #[serde(rename = "价格")]
    pub price: Option<f64>,
    #[serde(rename = "均价")]
    pub average_price: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
}

/// 上交所期权日线数据
/// 
/// 用于新浪接口的上交所期权历史日线数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct SseDaily {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
}

// ============ 商品期权数据 ============

/// 上期所期权历史数据
/// 
/// 上海期货交易所商品期权历史行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShfeOptionHist {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "前结算价")]
    pub prev_settle: Option<f64>,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "结算价")]
    pub settle: Option<f64>,
    #[serde(rename = "涨跌")]
    pub change: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
}

/// 上期所期权隐含波动率
/// 
/// 上海期货交易所商品期权隐含波动率数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct ShfeOptionVol {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "隐含波动率")]
    pub implied_volatility: Option<f64>,
}

/// 大商所期权历史数据
/// 
/// 大连商品交易所商品期权历史行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct DceOptionHist {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "前结算价")]
    pub prev_settle: Option<f64>,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "结算价")]
    pub settle: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
}

/// 郑商所期权历史数据
/// 
/// 郑州商品交易所商品期权历史行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CzceOptionHist {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "前结算价")]
    pub prev_settle: Option<f64>,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "结算价")]
    pub settle: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
}

/// 广期所期权历史数据
/// 
/// 广州期货交易所商品期权历史行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GfexOptionHist {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "前结算价")]
    pub prev_settle: Option<f64>,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "结算价")]
    pub settle: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
}

/// 广期所期权隐含波动率
/// 
/// 广州期货交易所商品期权隐含波动率数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct GfexOptionVol {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "隐含波动率")]
    pub implied_volatility: Option<f64>,
}

/// 新浪商品期权合约信息
/// 
/// 新浪财经商品期权合约基本信息
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommodityContract {
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "合约名称")]
    pub contract_name: String,
    #[serde(rename = "标的代码")]
    pub underlying_code: String,
    #[serde(rename = "期权类型")]
    pub option_type: String,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
}

/// 新浪商品期权T型报价
/// 
/// 新浪财经商品期权T型报价数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommodityContractTable {
    #[serde(rename = "看涨合约代码")]
    pub call_code: String,
    #[serde(rename = "看涨最新价")]
    pub call_last: Option<f64>,
    #[serde(rename = "看涨涨跌")]
    pub call_change: Option<f64>,
    #[serde(rename = "行权价")]
    pub strike: Option<f64>,
    #[serde(rename = "看跌合约代码")]
    pub put_code: String,
    #[serde(rename = "看跌最新价")]
    pub put_last: Option<f64>,
    #[serde(rename = "看跌涨跌")]
    pub put_change: Option<f64>,
}

/// 新浪商品期权历史数据
/// 
/// 新浪财经商品期权历史行情数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct CommodityOptionHist {
    #[serde(rename = "日期")]
    pub date: String,
    #[serde(rename = "开盘价")]
    pub open: Option<f64>,
    #[serde(rename = "最高价")]
    pub high: Option<f64>,
    #[serde(rename = "最低价")]
    pub low: Option<f64>,
    #[serde(rename = "收盘价")]
    pub close: Option<f64>,
    #[serde(rename = "成交量")]
    pub volume: Option<f64>,
}

// ============ 其他辅助数据 ============

/// 期权手续费信息
/// 
/// 各交易所期权合约的手续费标准
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionCommInfo {
    #[serde(rename = "交易所")]
    pub exchange: String,
    #[serde(rename = "品种")]
    pub product: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "开仓手续费")]
    pub open_fee: Option<f64>,
    #[serde(rename = "平仓手续费")]
    pub close_fee: Option<f64>,
    #[serde(rename = "手续费单位")]
    pub fee_unit: String,
}

/// 期权保证金信息
/// 
/// 各交易所期权合约的保证金标准
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionMargin {
    #[serde(rename = "交易所")]
    pub exchange: String,
    #[serde(rename = "品种")]
    pub product: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "保证金比例")]
    pub margin_rate: Option<f64>,
    #[serde(rename = "保证金金额")]
    pub margin_amount: Option<f64>,
}

/// 东方财富期权龙虎榜数据
/// 
/// 东方财富网期权龙虎榜单数据
#[derive(Debug, Clone, Serialize, Deserialize)]
pub struct OptionLhb {
    #[serde(rename = "交易类型")]
    pub trade_type: String,
    #[serde(rename = "交易日期")]
    pub trade_date: String,
    #[serde(rename = "证券代码")]
    pub security_code: String,
    #[serde(rename = "标的名称")]
    pub underlying_name: String,
    #[serde(rename = "合约代码")]
    pub contract_code: String,
    #[serde(rename = "合约名称")]
    pub contract_name: String,
    #[serde(rename = "持仓量")]
    pub open_interest: Option<f64>,
    #[serde(rename = "增减")]
    pub change: Option<f64>,
    #[serde(rename = "净持仓量")]
    pub net_position: Option<f64>,
    #[serde(rename = "占总交易量比例")]
    pub ratio: Option<f64>,
}

/// 东方财富期权价值分析数据类型别名
/// 
/// 与 OptionValueAnalysis 结构相同
pub type EmValueAnalysis = OptionValueAnalysis;

/// 东方财富期权风险分析数据类型别名
/// 
/// 与 OptionRiskAnalysis 结构相同
pub type EmRiskAnalysis = OptionRiskAnalysis;
